package container.impl;

import container.MyContext;
import container.MyHost;
import life.LifecycleBase;

public class MyMappedHost extends LifecycleBase implements MyHost {

    private String hostName;

    private String appBase;

    //context数组  context对应web项目
    private MyContext[] contexts = new MyContext[0];

    @Override
    public void setName(String hostName) {
        this.hostName = hostName;
    }

    @Override
    public String getName() {
        return hostName;
    }

    @Override
    public void setAppBase(String appBase) {
        this.appBase = appBase;
    }

    @Override
    public String getAppBase() {
        return appBase;
    }

    @Override
    public void setContexts(MyContext context) {
        MyContext result[] = new MyContext[contexts.length+1];
        System.arraycopy(this.contexts,0,result,0,this.contexts.length);
        result[contexts.length] = context;
        this.contexts = result;
    }

    @Override
    public MyContext[] getContexts() {
        return contexts;
    }

    @Override
    protected void initInternal() {
        for (MyContext context : contexts) {
            context.init();
        }
    }

    @Override
    protected void startInternal() {
        for (MyContext context : contexts) {
            context.start();
        }
    }
}
